package org.example;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author zhengdp
 * @Description
 * @Date 2022/9/20 23:32
 * @Created by zhengdp
 */
@Slf4j(topic = "c.FutureTest")
public class FutureTaskTest {
    @SneakyThrows
    public static void main(String[] args) {
        FutureTask<Integer> task = new FutureTask<>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.debug("running ....");
                Thread.sleep(10000);
                return 100;
            }
        });

        Thread t = new Thread(task,"t1");
        t.start();
        // 获取到线程结果 (阻塞等待）
        Integer integer = task.get();
        log.debug("t1线程执行结果:{}",integer);
    }
}
